/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ar.com.gruposicom.controller;

import ar.com.gruposicom.dao.CommandDao;
import ar.com.gruposicom.dao.PoliticDao;
import ar.com.gruposicom.dao.TrueValueDao;
import ar.com.gruposicom.dao.implement.CommandDaoImp;
import ar.com.gruposicom.dao.implement.PoliticDaoImp;
import ar.com.gruposicom.dao.implement.TrueValueDaoImp;
import ar.com.gruposicom.domain.Command;
import ar.com.gruposicom.domain.Politic;
import ar.com.gruposicom.domain.TrueValue;
import java.util.Iterator;

/**
 *
 * @author marcelo
 */
public class CommandCotroller 
{

    public CommandCotroller() 
    {
    }
    
    public void newCommand(Command cmd,int idOperation)
    {
        this.saveCommand(cmd, idOperation);
        this.savePolitics(cmd);
    }
    
    private void saveCommand(Command c, int idOperation)
    {
        CommandDao sql = new CommandDaoImp();
        sql.save(c, idOperation);
    }
    
    private void savePolitics(Command c)
    {
        Iterator<Politic> it = c.getPolitics().iterator();
        PoliticDao sql = new PoliticDaoImp();
        while(it.hasNext())
        {
            Politic p = it.next();
            sql.save(p, c.getId());
            this.saveValues(p);
        }
    }
    
    private void saveValues(Politic p)
    {
        Iterator<TrueValue> it = p.getTrueValues().iterator();
        TrueValueDao sql = new TrueValueDaoImp();
        while(it.hasNext())
        {
            sql.save(it.next(), p.getId());
        }
    }
    
}
